namespace SimpleWebServices.Web.UI.Html.Elements
{
    using System;
    using System.Xml;
    using System.Xml.Serialization;

    [XmlRoot("iframe")]
    public class InlineFrame : InnerElements, IXmlSerializable
    {
        public string Alignment
        {
            get;
            set;
        }

        public string FrameBorder
        {
            get;
            set;
        }

        public string Height
        {
            get;
            set;
        }

        public string LongDescription
        {
            get;
            set;
        }

        public string MarginHeight
        {
            get;
            set;
        }

        public string MarginWidth
        {
            get;
            set;
        }

        public string Name
        {
            get;
            set;
        }

        public string Scrolling
        {
            get;
            set;
        }

        public string Source
        {
            get;
            set;
        }

        public string Width
        {
            get;
            set;
        }

        public override IElement Deserialize(string name, string type, string xml)
        {
            IElement result = null;

            if (null == type && "iframe".Equals(name, StringComparison.OrdinalIgnoreCase))
            {
                result = xml.Deserialize<InlineFrame>();
            }

            return result;
        }

        public override void ReadXml(XmlReader reader)
        {
            string value = reader.GetAttribute("align");
            if (!string.IsNullOrEmpty(value))
            {
                this.Alignment = value;
            }

            value = reader.GetAttribute("frameborder");
            if (!string.IsNullOrEmpty(value))
            {
                this.FrameBorder = value;
            }

            value = reader.GetAttribute("height");
            if (!string.IsNullOrEmpty(value))
            {
                this.Height = value;
            }

            value = reader.GetAttribute("longdesc");
            if (!string.IsNullOrEmpty(value))
            {
                this.LongDescription = value;
            }

            value = reader.GetAttribute("marginheight");
            if (!string.IsNullOrEmpty(value))
            {
                this.MarginHeight = value;
            }

            value = reader.GetAttribute("marginwidth");
            if (!string.IsNullOrEmpty(value))
            {
                this.MarginWidth = value;
            }

            value = reader.GetAttribute("name");
            if (!string.IsNullOrEmpty(value))
            {
                this.Name = value;
            }

            value = reader.GetAttribute("scrolling");
            if (!string.IsNullOrEmpty(value))
            {
                this.Scrolling = value;
            }

            value = reader.GetAttribute("src");
            if (!string.IsNullOrEmpty(value))
            {
                this.Source = value;
            }

            value = reader.GetAttribute("width");
            if (!string.IsNullOrEmpty(value))
            {
                this.Width = value;
            }

            base.ReadXml(reader);
        }

        public override void WriteXml(XmlWriter writer)
        {
            if (!string.IsNullOrEmpty(this.Alignment))
            {
                writer.WriteAttributeString("align", this.Alignment);
            }

            if (!string.IsNullOrEmpty(this.FrameBorder))
            {
                writer.WriteAttributeString("frameborder", this.FrameBorder);
            }

            if (!string.IsNullOrEmpty(this.Height))
            {
                writer.WriteAttributeString("height", this.Height);
            }

            if (!string.IsNullOrEmpty(this.LongDescription))
            {
                writer.WriteAttributeString("longdesc", this.LongDescription);
            }

            if (!string.IsNullOrEmpty(this.MarginHeight))
            {
                writer.WriteAttributeString("marginheight", this.MarginHeight);
            }

            if (!string.IsNullOrEmpty(this.MarginWidth))
            {
                writer.WriteAttributeString("marginwidth", this.MarginWidth);
            }

            if (!string.IsNullOrEmpty(this.Name))
            {
                writer.WriteAttributeString("name", this.Name);
            }

            if (!string.IsNullOrEmpty(this.Scrolling))
            {
                writer.WriteAttributeString("scrolling", this.Scrolling);
            }

            if (!string.IsNullOrEmpty(this.Source))
            {
                writer.WriteAttributeString("src", this.Source);
            }

            if (!string.IsNullOrEmpty(this.Width))
            {
                writer.WriteAttributeString("width", this.Width);
            }

            base.WriteXml(writer);
        }
    }
}